
$(function() {
	Tip.emp('员工');	
});

function _reset(form) {
	$(form).resetForm();
	// alert("OK.");
	
	var s = $("div[id^='result']:visible");	
	var result = s[0].id;
	$('#'+result).html('');
}

var Password = {	
	dialog_add_: function(url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_add")[0];
	
				var body = { };
				body.emp = form.emp.value;
				body.type = form.type.value;
				body.password = form.password.value;
				body.content = form.content.value;
	
				$(this).dialog("close");
	
				$.post('emp.php?do=Password.addPost', body, function(data) {					
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	dialog_edit_: function(url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_edit")[0];

				var body = {};
				body.id = form.id.value;
				body.emp = form.emp.value;
				body.type = form.type.value;
				body.password = form.password.value;
				body.content = form.content.value;

				$(this).dialog("close");
				
				var url = 'emp.php?do=Password.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},
	
	popup: function(e, p2, id, status) {
		$.cookie('id_', id);

		$.cookie('status_', status);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'emp.php?do=Password.edit&id=' + id;	
		var c2 = 'emp.php?do=Password.view&id=' + id;

		var a1 = ['编辑信息', 'url', 'Password.dialog_edit_', '550x320'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '550x320'];
			
		var s = c1 + ", " + c2;

		return popup(e, [a1, a2], s);
	}
};